import { Component } from 'react'
// 引入Navigate组件,用于重定向
import {createBrowserRouter, Navigate} from 'react-router-dom'
// 引入main.js页面
import Main from '../pages/main'
// 引入home.js页面,如果文件夹下有index.js文件，则可以省略index.js   
import Home from '../pages/home'    
import Mall from '../pages/mall'
import User from '../pages/user'
import PageOne from '../pages/other/pageOne'
import PageTwo from '../pages/other/pageTwo'
import Login from '../pages/login'

// 用配置的方式来定义路由
const routes =[
    {
        path:'/',
        Component:Main,
        // 创建一个子路由
        children:[
            {   
                index: true,  // 将此路由标记为父路由的默认子路由
                element: <Navigate to="/home" replace />
            },
            {   
                path:'home',
                Component:Home
            },
            {
                path:'mall',
                Component:Mall
            },
            {
                path:'user',
                Component:User
            },
            {
                path:'other',
                children:[
                    {
                        path:'pageOne',
                        Component:PageOne
                    },
                    {
                        path:'pageTwo',
                        Component:PageTwo
                    }
                ]   
            }
        ]
    },
    {
        path:'/login',
        Component:Login
    }
]

// 对外暴露当前路由的一个对象
export default createBrowserRouter(routes);